package br.ucb.ucblive.HIB;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.ucb.ucblive.beans.MensagemUsuario;
import br.ucb.ucblive.beans.MensagemUsuarioPK;

public class MensagemUsuarioHIB {

	
	public void salvar(MensagemUsuario obj) {
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		session.saveOrUpdate(obj);
		transaction.commit();
		session.close();
	}

	public void excluir(MensagemUsuario obj) {
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		session.delete(obj);
		transaction.commit();
		session.close();
		
	}

	@SuppressWarnings("unchecked")
	public List<MensagemUsuario> listar() {
		Session session = HibernateUtil.getSession();
		try {
			return session.createCriteria(MensagemUsuario.class).list();
		} finally {
			session.close();
		}
	}
	
	public MensagemUsuario consultar(MensagemUsuarioPK id) {
		Session session = HibernateUtil.getSession();
		try {
			MensagemUsuario obj = (MensagemUsuario) session.get(MensagemUsuario.class,id);
			return obj;
		} finally {
			session.close();
		}
	}
}
